<?php
namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "game_info".
 *
 * @property string $game_id
 * @property string $game_name
 * @property string $seo_title
 * @property string $seo_keyword
 * @property string $seo_description
 * @property string $game_detail
 * @property string $game_album
 * @property string $game_banner
 * @property string $m_tongji_code
 * @property string $tongji_code
 * @property string $basic_information
 * @property integer $created_at
 * @property integer $updated_at
 */
class GameInfo extends \yii\db\ActiveRecord
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'game_info';
    }

    /*
     * 产生创建日期和更新日期时间戳
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => 'updated_at'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                [
                    'game_id',
                    //'game_name',
                    //'game_album'
                ],
                'required'
            ],
            [
                [
                    'game_id',
                    'created_at',
                    'updated_at'
                ],
                'integer'
            ],
            [
                [
                    'game_detail',
                    'game_album',
                    'basic_information'
                ],
                'string'
            ],
            [
                [
                    'game_name',
                    'seo_title',
                    'seo_keyword',
                    'seo_description',
                    'game_banner',
                    'm_tongji_code',
                    'tongji_code'
                ],
                'string',
                'max' => 255
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'game_id' => '游戏ID',
            'game_name' => '游戏名称',
            'seo_title' => 'SEO标题',
            'seo_keyword' => 'SEO关键词',
            'seo_description' => 'SEO描述',
            'game_detail' => '游戏详情',
            'game_album' => '游戏相册',
            'game_banner' => '游戏banner',
            'm_tongji_code' => '统计标识',
            'tongji_code' => '统计代码',
            'basic_information' => '基本资料&信息导航',
            'created_at' => '创建时间',
            'updated_at' => '更新时间'
        ];
    }

    // relationship
    /**
     * 所属游戏
     */
    public function getGame()
    {
        return $this->hasOne(Game::className(), [
            'game_id' => 'game_id'
        ]);
    }

    /**
     * 游戏Bete[一对多]
     */
    public function getBetas()
    {
        return $this->hasMany(GameBeta::className(), [
            'game_id' => 'game_id'
        ]);
    }

    /**
     * 游戏Notice[一对多]
     */
    public function getNotices()
    {
        return $this->hasMany(GameNotice::className(), [
            'game_id' => 'game_id'
        ]);
    }

    /**
     * 游戏的version信息[一对多]
     */
    public function getVersions()
    {
        return $this->hasMany(GameVersion::className(), [
            'game_id' => 'game_id'
        ]);
    }
}
